// src/api/vendor.ts
import request from '@/utils/request'

export interface VendorPayload {
  id?: number
  address: string
  code: string
  contact: string
  name: string
  settleCycle: string
  taxNo: string
  terms: string
}

/**
 * 供应商列表
 * GET /api/vendor/list
 * @returns {Promise<any>} 响应：{"code":0,"message":"success","data":[...]}
 */
export function listVendors(): Promise<any> {
  return request({
    url: '/api/vendor/list',
    method: 'get',
  })
}

/**
 * 新增供应商
 * POST /api/vendor
 * @param {Object} data
 * @param {string} data.address
 * @param {string} data.code
 * @param {string} data.contact
 * @param {string} data.name
 * @param {string} data.settleCycle
 * @param {string} data.taxNo
 * @param {string} data.terms
 * @returns {Promise} 响应：{"code":0,"message":"success","data":1}
 */
export function createVendor(data: VendorPayload): Promise<any> {
  return request({
    url: '/api/vendor',
    method: 'post',
    data,
  })
}

/**
 * 修改供应商信息
 * PUT /api/vendor
 * @param {Object} data
 * @param {number} data.id
 * @param {string} data.address
 * @param {string} data.code
 * @param {string} data.contact
 * @param {string} data.name
 * @param {string} data.settleCycle
 * @param {string} data.taxNo
 * @param {string} data.terms
 * @returns {Promise} 响应：{"code":0,"message":"success","data":1}
 */
export function updateVendor(data: VendorPayload): Promise<any> {
  return request({
    url: '/api/vendor',
    method: 'put',
    data,
  })
}

/**
 * 删除供应商
 * DELETE /api/vendor/{id}
 * @param {number|string} id 供应商ID
 * @returns {Promise} 响应：{"code":0,"message":"success","data":1}
 */
export function deleteVendor(id: number | string): Promise<any> {
  return request({
    url: `/api/vendor/${id}`,
    method: 'delete',
  })
}